package com.ant.order.service;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.stereotype.Service;

@Service
public class KafkaTestService {
    @KafkaListener(topics = "test", groupId = "console-consumer-67125",
    topicPartitions = {
            @TopicPartition(topic = "test",
            partitions = {"0","1"})
    })
    public void kafkaTest(ConsumerRecord<String, String> consumerRecord){
        System.out.println("消费者console-consumer-67125消息：" + consumerRecord.value());
    }

    @KafkaListener(topics = "test", groupId = "test-group",
            topicPartitions = {
            @TopicPartition(    //指定分区消费
                    topic = "test",
                    partitions = {"2"})})
    public void kafkaConsumerGroupTest(ConsumerRecord<String, String> consumerRecord){
        System.out.println("消费者test-group消费消息：" + consumerRecord.value());
    }
}
